var removeKdigits = function (num, k) {
    const stack = [];

    for (let s of num.toString()) {
        if (k === 0) {
            stack.push(s)
        } else
            if (!stack.length) {
                stack.push(s)
            } else {
                let end = stack[stack.length - 1];
                console.log(s, end);
                if (end > s) {
                    stack.pop();
                    stack.push(s);
                    k--;
                } else {
                    stack.push(s)
                }
            }

    }
    console.log(stack)
};
removeKdigits('0432219', 3)
